package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("login")
public class LoginController {

    @Autowired
    private UserService userService;


    @RequestMapping("login")
    public String login (String userName , String password, HttpSession session){
        if (userName!=null && password!=null){
            User user=userService.findByName(userName,password);
            session.setAttribute("user",user);
            return "redirect:/user/findAll";
        }
        return "login";
    }
}
